<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-08-25 14:12
 *
 * Version: 2.0
 */

namespace App\Modules\DataCenter\Transformers;


use League\Fractal\TransformerAbstract;

class getStoreHeaderInfoTransformer extends TransformerAbstract
{
	public $params;

	public function __construct($store)
	{
		$this->params = $store;
	}

	public function transformer()
	{
		return isset($this->params) ? [
			"id"            => isset($this->params->storeRank[0]) ? $this->params->storeRank[0]->id : 0,
			"store_id"      => $this->params->id,
			"adcode"        => $this->params->adcode,
			"rank_date"     => isset($this->params->storeRank[0]) ?  date('Y-m-d',$this->params->storeRank[0]->rank_date) : null,
			"level"         => isset($this->params->storeRank[0]) ?  $this->params->storeRank[0]->level : 0,
			"value"         => isset($this->params->total_amount) ?  $this->params->total_amount : 0,
			"compare_count" => isset($this->params->storeRank[0]) ?  $this->params->storeRank[0]->compare_count : 0,
			"order_sum"     => isset($this->params->total_order_sum) ?  $this->params->total_order_sum : 0,
			"profit_sum"    => isset($this->params->profit_sum) ?  $this->params->profit_sum : 0,
			"store"         => [
				"id"    => $this->params->id,
				"name"  => $this->params->name,
				"logo"  => isset($this->params->picture) ? $this->params->picture->image : null,
				"level" => $this->params->level
			]
		] : null;
	}

}